/*  _________________________________________
   /                                      /_ \
  |            User Movement             |/ \ |
  |                                      |___||
   \______________________________________\_/ |
	   |                                      |
      /     User Movement Input              /
     /     Written April, 2009              /
    |     by Darrell Eastman.              |___
    |                                      |   |
     \______________________________________\_/
*/

#include <irrlicht.h>
#include "input.h"
#include "scenetype.h"

/*
The event receiver for keeping the pressed keys is ready, the actual responses
will be made inside the render loop, right before drawing the scene. So lets
just create an IrrlichtDevice and the scene node we want to move. We also
create some other additional scene nodes, to show that there are also some
different possibilities to move and animate scene nodes.
*/

IEventReceiver  *receiver   = IrrDevice::getIEventReceiver();

//For Each User
for each( user Ply in list user::Cnt())
{
	//Controller Direction Normal
	Ply.ConDir.Set( 0, 0 );
	//Controller
	Ply.ConSpd = 0;

	//Crouch
	if( receiver.IsKeyUpDown( EKEY_KEY_C ) && Ply.Ste = "Stand" )
		Ply.Ste = "Crouch";

	//Right
	if( receiver.IsKeyDown( EKEY_KEY_D )) {
		Ply.ConDir.PlusEqVect( vector2df( -1, 0 ));
		Ply.ConSpd = 1;
		if( Ply.Ste = "Stand" )
			Ply.Ste = "Walk";
		else if( Ply.Ste = "Crouch" )
			Ply.Ste = "Crawl";
	}

	//Left
	if( receiver.IsKeyDown( EKEY_KEY_A )) {
		Ply.ConDir.PlusEqVect( vector2df( 1, 0 ));
		Ply.ConSpd = 1;
		if( Ply.Ste = "Stand" )
			Ply.Ste = "Walk";
		else if( Ply.Ste = "Crouch" )
			Ply.Ste = "Crawl";
	}

	//Forward
	if( receiver.IsKeyDown( EKEY_KEY_W )) {
		Ply.ConDir.PlusEqVect( vector2df( 0, -1 ));
		Ply.ConSpd = 1;
		if( Ply.Ste = "Stand" )
			Ply.Ste = "Walk";
		else if( Ply.Ste = "Crouch" )
			Ply.Ste = "Crawl";
	}

	//Backward
	if( receiver.IsKeyDown( EKEY_KEY_S )) {
		Ply.ConDir.PlusEqVect( vector2df( 0, 1 ))
		Ply.ConSpd = 1
		if( Ply.Ste = "Stand")
			Ply.Ste = "Walk";
		else if( Ply.Ste = "Crouch" )
			Ply.Ste = "Crawl";
	}

	//Run
	if( receiver.IsKeyDown( EKEY_SHIFT ) && Ply.Ste = "Walk" )
		Ply.Ste = "Run";

	//Jump
	if( receiver.IsKeyUpDown( EKEY_SPACE ) && Ply.Ste ! "Fall" )
		Ply.Jump();

	//Use
	if( receiver.IsKeyUpDown( EKEY_KEY_E ) && Ply.Ste ! "Fall" && Ply.Ste ! "Climbing" )
		Ply.Use();

	//Action
	if( receiver.IsKeyDown( EKEY_CONTROL ) &&
		Ply.Ste ! "Climb" &&
		Ply.Ste ! "Leap" &&
		Ply.Ste ! "Spring")
		Ply.ActionPri();

	//Weapon Select Next
	if( receiver.IsKeyUpDown( EKEY_PERIOD )) {
		Amm[3] += 1;
		if( Amm[3] > 1 ) Amm[3] = 0;
	}

	//Weapon Select Previous
	if( receiver.IsKeyUpDown( EKEY_COMMA )) {
		Amm[3] -= 1;
		if( Amm[3] < 0 ) Amm[3] = 1;
	}
}

gameEvent( stringw GamSte, list Usr )
{
	switch( GamSte )
	{
		case "Scavenge":
		case "Escort":
		case "Pillage":
		case "Mutany":
		default:
	}

	return GamSte;
}
